<?php
if ( !defined('IN_SEC') ){exit();}
?>
<?php include template("admin_header");?>
				<div class="main-content">
					<div class="breadcrumbs" id="breadcrumbs">
						<script type="text/javascript">
							try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
						</script>
<?php include template("admin_breadcrumb");?>
					</div>

					<div class="page-content">
						<div class="page-header">
							<h1><?php echo $_G['admincp']['actname']; ?><small><i class="icon-double-angle-right"></i><?php echo $_G['admincp']['optname']; ?></small></h1>
						</div><!-- /.page-header -->

						<div class="row">
							<div class="col-xs-12">
								<!-- PAGE CONTENT BEGINS -->
									<div class="col-sm-12">
										<div class="tabbable">
											<ul class="nav nav-tabs" id="myTab">
												<li><a data-toggle="tab" href="#home"><i class="green icon-home bigger-110"></i>基本信息</a></li>
												<li class="active"><a data-toggle="tab" href="#profile">联系记录<span class="badge badge-danger"><?php echo $contact_count; ?></span></a></li>
												<li><a data-toggle="tab" href="#log">客户日志</a></li>
												<li><a data-toggle="tab" href="#teams">项目列表</a></li>
												<li class="dropdown">
													<a data-toggle="dropdown" class="dropdown-toggle" href="javascript:void(0);">操作 &nbsp;<i class="icon-caret-down bigger-110 width-auto"></i></a>
													<ul class="dropdown-menu dropdown-info">
														<li><a href="?action=customer&operation=edit&id=<?php echo $customer['id']; ?>"><i class="icon-edit bigger-120"></i>编辑</a></li>
														<li><a data-toggle="tab" class="ajaxlink" href="?action=customer&operation=delete&id=<?php echo $customer['id']; ?>" ask="确定要删除该客户"><i class="icon-trash bigger-120"></i>删除</a></li>
													</ul>
												</li>
											</ul>

											<div class="tab-content">
												<div id="home" class="tab-pane">

                                                    <div class="widget-box">
                                                        <div class="widget-header widget-header-flat">
                                                            <h4 class="smaller">
                                                                <i class="icon-quote-left smaller-80"></i><?php echo $customer['name']; ?>
                                                            </h4>
                                                            <div class="widget-toolbar">
                                                                <label>
                                                                    <small class="green">
                                                                        <b>表格</b>
                                                                    </small>
    
                                                                    <input id="id-check-switch" type="checkbox" class="ace ace-switch ace-switch-6">
                                                                    <span class="lbl"></span>
                                                                </label>
                                                            </div>
                                                        </div>

                                                        <div class="widget-body">
                                                            <div class="widget-main">
                                                                <div class="row switch-div switch-row">
                                                                    <div class="col-xs-12">
                                                                        <blockquote>
                                                                            <p>一个由 <strong><?php echo heivrid($admincp->admins[$customer['creatorid']]); ?></strong> 创建，现由 <strong><?php echo $customer['adminid'] ? heivrid($admincp->admins[$customer['adminid']]) : '客户池'; ?></strong> 负责跟进的 <strong><?php echo $status[$customer['status']]; ?></strong> </p>
                                                                            <p>
                                                                                该公司性质为 <strong><?php echo $natures[$customer['nature']] ? $natures[$customer['nature']] : '未知'; ?></strong>
            <?php if($customer['demands']){?>
            需求意向有 <strong><?php echo join('、', $customer_demands); ?></strong>
            <?php }?>
                                                                            </p>
            <?php if($customer['address']){?>
                                                                            <p>
                                                                                该公司地址位于 <strong><?php echo $customer['address']; ?></strong>
                                                                            </p>
            <?php }?>

            <?php if($customer['contact_name']){?>
                                                                            <p>
                                                                                该公司 <strong><?php echo $customer['contact_job'] ? $jobs[$customer['contact_job']] : '联系人'; ?></strong> 姓名 <strong><?php echo $customer['contact_name']; ?></strong>
                <?php if($customer['contact_tel']){?>
                                                                                ，固话：<strong><?php echo $customer['contact_tel']; ?></strong>
                <?php }?>
                <?php if($customer['contact_phone']){?>
                                                                                ，手机：<strong><?php echo $customer['contact_phone']; ?></strong>
                <?php }?>
                <?php if($customer['contact_email']){?>
                                                                                ，邮件：<strong><?php echo $customer['contact_email']; ?></strong>
                <?php }?>
                <?php if($customer['contact_qq']){?>
                                                                                ，QQ：<strong><?php echo $customer['contact_qq']; ?></strong>
                <?php }?>

                                                                            </p>
            <?php }?>
            <?php if($customer['address']){?>
                                                                            <p>
                                                                                该公司地址位于 <strong><?php echo $customer['address']; ?></strong>
                                                                            </p>
            <?php }?>
            <?php if($customer['detail']){?>
                                                                            <p>
                                                                                该客户备注： <strong><?php echo $customer['detail']; ?></strong>
                                                                            </p>
            <?php }?>

            <?php if($customer['last_contact_time']){?>
                                                                            <p>最近一个月内沟通过 <strong class="red"><?php echo $contact_count_by_month; ?></strong> 次</p>
                                                                            <p>最后一次沟通时间为 <strong><?php echo date('Y-m-d H:i:s', $customer['last_contact_time']); ?></strong></p>
            <?php } else { ?>
                                                                            <p><strong class="red">目前还没有进行沟通</strong></p>
            <?php }?>
                                                                            <small>
                                                                                <cite title="Source Title">由智能OA提供的简单概述</cite>
                                                                            </small>
                                                                        </blockquote>
                                                                    </div>
                                                                </div>
                                                                <div class="row switch-div switch-table hide">
                                                                    <div class="profile-user-info profile-user-info-striped">

                                                                        <div class="profile-info-row">
                                                                            <div class="profile-info-name"> 创建人 </div>
                        
                                                                            <div class="profile-info-value">
                                                                                <span><a href="?action=account&operation=profile&heivrid=<?php echo $admincp->admins[$customer['creatorid']]['username']; ?>&profile=yes" target="_blank"><?php echo heivrid($admincp->admins[$customer['creatorid']]); ?></a></span>
                                                                            </div>
                                                                        </div>

                                                                        <div class="profile-info-row">
                                                                            <div class="profile-info-name"> 客户负责人 </div>
                        
                                                                            <div class="profile-info-value">
                                                                                <span><a href="?action=account&operation=profile&heivrid=<?php echo $admincp->admins[$customer['adminid']]['username']; ?>&profile=yes" target="_blank"><?php echo $customer['adminid'] ? heivrid($admincp->admins[$customer['adminid']]) : '客户池'; ?></a></span>
                                                                            </div>
                                                                        </div>

                                                                        <div class="profile-info-row">
                                                                            <div class="profile-info-name"> 客户名称 </div>
                        
                                                                            <div class="profile-info-value">
                                                                                <span class="editable" id="name"><?php echo $customer['name']; ?></span>
                                                                            </div>
                                                                        </div>

                                                                        <div class="profile-info-row">
                                                                            <div class="profile-info-name"> 客户状态 </div>
                        
                                                                            <div class="profile-info-value">
                                                                                <span class="editable use-select2" id="status" data="<?php echo $customer['status']; ?>"><?php echo $status[$customer['status']]; ?></span>
                                                                            </div>
                                                                        </div>

                                                                        <div class="profile-info-row">
                                                                            <div class="profile-info-name"> 客户性质 </div>
                        
                                                                            <div class="profile-info-value">
                                                                                <span class="editable use-select2" id="nature" data="<?php echo $customer['nature']; ?>"><?php echo $customer['nature'] ? $natures[$customer['nature']] : '未知'; ?></span>
                                                                            </div>
                                                                        </div>

                                                                        <div class="profile-info-row">
                                                                            <div class="profile-info-name"> 需求意向 </div>
                        
                                                                            <div class="profile-info-value">
                                                                                <span id="demands"><?php echo $customer_demands ? join('、', $customer_demands) : '暂无'; ?></span>
                                                                            </div>
                                                                        </div>

                                                                        <div class="profile-info-row">
                                                                            <div class="profile-info-name"> 客户网站 </div>
                        
                                                                            <div class="profile-info-value">
                                                                                <span class="editable" id="url"><?php echo $customer['url'] ? $customer['url'] : '无'; ?></span>
                                                                            </div>
                                                                        </div>

                                                                        <div class="profile-info-row">
                                                                            <div class="profile-info-name"> 客户地域 </div>
                        
                                                                            <div class="profile-info-value">
                                                                                <i class="icon-map-marker light-orange bigger-110"></i>
                                                                                <span class="editable" id="province" data="<?php echo $customer['province']; ?>"><?php echo $customer['province_name'] ? $customer['province_name'] : '未知省份'; ?></span>
                                                                                <span class="editable" id="city" data="<?php echo $customer['city']; ?>"><?php echo $customer['city_name'] ? $customer['city_name'] : '未知城市'; ?></span>
                                                                            </div>
                                                                        </div>
                        
                                                                        <div class="profile-info-row">
                                                                            <div class="profile-info-name"> 客户地址 </div>
                        
                                                                            <div class="profile-info-value">
                                                                                <span class="editable" id="address"><?php echo $customer['address'] ? $customer['address'] : '未知'; ?></span>
                                                                            </div>
                                                                        </div>

                                                                        <div class="profile-info-row">
                                                                            <div class="profile-info-name"> 联系人姓名 <i class="icon-heart light-blue"></i></div>
                        
                                                                            <div class="profile-info-value">
                                                                                <span class="editable" id="contact_name"> <?php echo $customer['contact_name'] ? $customer['contact_name'] : '暂无'; ?></span>
                                                                            </div>
                                                                        </div>
                        
                                                                        <div class="profile-info-row">
                                                                            <div class="profile-info-name"> 联系人职位 <i class="icon-group light-blue"></i></div>
                        
                                                                            <div class="profile-info-value">
                                                                                <span class="editable" id="contact_job" data="<?php echo $customer['contact_job']; ?>"><?php echo $customer['contact_job'] ? $jobs[$customer['contact_job']] : '暂无'; ?></span>
                                                                            </div>
                                                                        </div>
                        
                                                                        <div class="profile-info-row">
                                                                            <div class="profile-info-name"> 联系人固话 <i class="icon-phone light-blue"></i></div>
                        
                                                                            <div class="profile-info-value">
                                                                                <span class="editable" id="contact_tel"><?php echo $customer['contact_tel'] ? $customer['contact_tel'] : '暂无'; ?></span>
                                                                            </div>
                                                                        </div>

                                                                        <div class="profile-info-row">
                                                                            <div class="profile-info-name"> 联系人手机 <i class="icon-mobile-phone bigger-120 light-blue"></i></div>
                        
                                                                            <div class="profile-info-value">
                                                                                <span class="editable" id="contact_phone"><?php echo $customer['contact_phone'] ? $customer['contact_phone'] : '暂无'; ?></span>
                                                                            </div>
                                                                        </div>

                                                                        <div class="profile-info-row">
                                                                            <div class="profile-info-name"> 联系人邮箱 <i class=" icon-envelope-alt light-blue"></i></div>
                        
                                                                            <div class="profile-info-value">
                                                                                <span class="editable" id="contact_email"><?php echo $customer['contact_email'] ? $customer['contact_email'] : '暂无'; ?></span>
                                                                            </div>
                                                                        </div>

                                                                        <div class="profile-info-row">
                                                                            <div class="profile-info-name"> 联系人QQ </div>
                        
                                                                            <div class="profile-info-value">
                                                                                <span class="editable" id="contact_qq"><?php echo $customer['contact_qq'] ? $customer['contact_qq'] : '暂无'; ?></span>
                                                                            </div>
                                                                        </div>

                                                                    </div>
                                                                </div>

                                                                <hr />
                                                                <address>
                                                                    <strong>Heivr, Tech.</strong>
                                                                </address>
                                                                <address>
            <?php if($customer['url']){?>
                                                                    <a href="http://tech.heivr.com/" target="_blank">http://tech.heivr.com/</a>
            <?php }?>
                                                                </address>
                                                            </div>
                                                        </div>
                                                    </div>

												</div>

												<div id="profile" class="tab-pane in active">
                                                	<form id="contact-form" action="?action=customer&operation=edit&act=insert_contact&id=<?php echo $customer['id']; ?>" method="post" enctype="multipart/form-data">
                                                    	<div class="contact-files hide"></div>
                                                        <h4 class="header green clearfix">新沟通记录</h4>
                                                        <label class="control-label" for="form-field-1"> 沟通方式</label>
    <?php if(is_array($contact_types)){foreach($contact_types AS $k=>$v) { ?>
                                                        <input name="type" type="radio" value="<?php echo $k; ?>" class="ace"><span class="lbl"> <?php echo $v; ?></span>
    <?php }}?>
    													<div class="row">
                                                            <div class="col-sm-1">
                                                                <label class="control-label" for="form-field-2"> 下次沟通日期</label>
                                                                <input name="next-contact-time" type="text" value="" class="form-control date-picker" data-date-format="yyyy-mm-dd">
                                                            </div>
														</div>
                                                        <div class="widget-box">
                                                            <div class="widget-header widget-header-small header-color-blue">  </div>
                
                                                            <div class="widget-body">
                                                                <div class="widget-main no-padding">
                                                                    <textarea class="span12" name="content" data-provide="markdown" rows="10"></textarea>
                                                                </div>
                
                                                                <div class="widget-toolbox padding-4 clearfix">
                                                                    <div class="btn-group pull-left">
                                                                        <button class="btn btn-sm btn-info">
                                                                            <i class="icon-remove bigger-125"></i>重填
                                                                        </button>
                                                                    </div>
                
                                                                    <div class="btn-group pull-right">
                                                                        <button class="btn btn-sm btn-purple btn-post-one">
                                                                            <i class="icon-save bigger-125"></i>保存
                                                                        </button>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </form>
													<div class="row">
                                                        <div class="col-xs-12">
                                                            <div id="dropzone">
                                                                <form action="?action=customer&operation=edit&detail=yes&id=<?php echo $customer['id']; ?>&act=upload_file" class="dropzone">
                                                                    <div class="fallback">
                                                                        <input name="file" type="file" multiple="" />
                                                                    </div>
                                                                </form>
                                                            </div>
                                                        </div>
                                                    </div>
													<div class="hr hr-24"></div>
                                                    <div class="timeline-container">
<?php if(is_array($contacts)){foreach($contacts AS $contactk=>$contactv) { ?>
                                                        <div class="timeline-label">
                                                            <span class="label label-primary arrowed-in-right label-lg">
                                                                <b><?php echo date('Y-m-d') == $contactk ? '今天' : $contactk; ?></b>
                                                            </span>
                                                        </div>
        
                                                        <div class="timeline-items">
<?php if(is_array($contactv)){foreach($contactv AS $k=>$v) { ?>
                                                            <div class="timeline-item clearfix">
                                                                <div class="timeline-info">
                                                                    <img src="<?php echo avatar($admincp->admins[$v['adminid']]['avatar']); ?>" />
                                                                    <span class="label label-info label-sm"><?php echo date('H:i', $v['create_time']); ?></span>
                                                                </div>
                                                                <div class="widget-box transparent">
                                                                    <div class="widget-header widget-header-small">
                                                                        <h5 class="smaller">
                                                                            <a href="?action=account&operation=profile&heivrid=<?php echo $admincp->admins[$v['adminid']]['username']; ?>&profile=yes" class="blue"><?php echo heivrid($admincp->admins[$v['adminid']]); ?></a>
                                                                            <span class="grey">通过 <?php echo $contact_types[$v['type']]; ?> 联系</span>
                                                                        </h5>
        
                                                                        <span class="widget-toolbar no-border">
                                                                            <i class="icon-time bigger-110"></i> <?php echo date('Y-m-d H:i:s', $v['create_time']); ?>
                                                                        </span>

                                                                        <span class="widget-toolbar">
                                                                            <a href="#" data-action="reload">
                                                                                <i class="icon-refresh"></i>
                                                                            </a>
        
                                                                            <a href="#" data-action="collapse">
                                                                                <i class="icon-chevron-up"></i>
                                                                            </a>
                                                                        </span>
                                                                    </div>
        
                                                                    <div class="widget-body">
                                                                        <div class="widget-main">
                                                                            <?php echo $v['content']; ?>
                                                                            <div class="space-6"></div>
                                                                            <div class="widget-toolbox clearfix">
                                                                                <div class="pull-right action-buttons">
                                                                                    <a href="#">
                                                                                        <i class="icon-ok green bigger-130"></i>
                                                                                    </a>
        
                                                                                    <a href="#">
                                                                                        <i class="icon-pencil blue bigger-125"></i>
                                                                                    </a>
        
                                                                                    <a href="#">
                                                                                        <i class="icon-remove red bigger-125"></i>
                                                                                    </a>
                                                                                </div>
                                                                            </div>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>
<?php $files = $v['files'] ? json_decode($v['files'], true) : array();; ?>
<?php if($files){?>
                                                            <div class="timeline-item clearfix">
                                                                <div class="timeline-info">
                                                                    <i class="timeline-indicator icon-file btn btn-danger no-hover"></i>
                                                                </div>
        
                                                                <div class="widget-box">
                                                                    <div class="widget-header header-color-red2 widget-header-small">
                                                                        <h5 class="smaller">附件</h5>
        
                                                                        <span class="widget-toolbar no-border">
                                                                            <i class="icon-time bigger-110"></i>
                                                                        </span>
        
                                                                        <span class="widget-toolbar">
                                                                            <a href="javascript:void(0);" data-action="reload"><i class="icon-refresh"></i></a>
                                                                            <a href="javascript:void(0);" data-action="collapse"><i class="icon-chevron-up"></i></a>
                                                                        </span>
                                                                    </div>
        
                                                                    <div class="widget-body">
                                                                        <div class="widget-main clearfix">
                                                                            <div class="pull-left">
<?php if(is_array($files)){foreach($files AS $k=>$v) { ?>
<?php $name_pos = strpos($v, '-');$name = substr($v, $name_pos ? ($name_pos + 1) : 0); ?>
                                                                                <a data-rel="tooltip" title="<?php echo $name; ?>" href="<?php echo $v; ?>" target="_blank"><i class="icon-file bigger-110"></i> <span class="black"><?php echo $name; ?></span></a>
<?php }}?>
                                                                            </div>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>
<?php }?>
<?php }}?>
                                                        </div><!-- /.timeline-items -->
<?php }}?>
                                                    </div>
												</div>

												<div id="log" class="tab-pane">
                                                	<div class="tab-content">
                                                    	<div class="row">
                                                            <table class="table table-striped table-hover" style="text-align:center;">
                                                                <thead class="thin-border-bottom table-border-top">
                                                                    <tr>
                                                                        <td class="hidden-480">操作人</td>
                                                                        <td>事件</td>
                                                                        <td class="hidden-480">时间</td>
                                                                    </tr>
                                                                </thead>
                                                                <tbody>
<?php if(is_array($customer_logs)){foreach($customer_logs AS $k=>$v) { ?>
                                                                    <tr>
                                                                        <td class="hidden-480"><?php echo heivrid($admincp->admins[$v['adminid']]); ?></td>
                                                                        <td><?php echo $v['title']; ?></td>
                                                                        <td class="hidden-480"><?php echo date('Y-m-d H:i:s', $v['create_time']); ?></td>
                                                                    </tr>
<?php }}?>
                                                                </tbody>
                                                            </table>
                                                        </div>
                                                    </div>
												</div>

												<div id="teams" class="tab-pane">
                                                	<div class="tab-content">
                                                        <div class="profile-users clearfix">
<?php if(is_array($customer_teams)){foreach($customer_teams AS $k=>$v) { ?>
															<div class="itemdiv memberdiv">
                                                                <div class="inline position-relative">
                                                                    <div class="user">
                                                                        <a href="index.php?action=team&operation=edit&detail=yes&id=2"><i class="icon-time middle bigger-150"></i></a>
                                                                    </div>
    
                                                                    <div class="body">
                                                                        <div class="name">
                                                                            <a href="index.php?action=team&operation=edit&detail=yes&id=2"><span class="user-status status-online"></span><?php echo $v['name']; ?></a>                                                                                            </a>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>
<?php }}?>
														</div>
                                                    </div>
												</div>
											</div>
										</div>
									</div>
								<!-- PAGE CONTENT ENDS -->
							</div><!-- /.col -->
						</div><!-- /.row -->
					</div><!-- /.page-content -->
				</div>
<?php include template("admin_footer");?>
		<!-- page specific plugin scripts -->
		<link rel="stylesheet" href="/static/ace/assets/css/dropzone.css" />
		<link rel="stylesheet" href="/static/ace/assets/css/bootstrap-editable.css" />
		<link rel="stylesheet" href="/static/ace/assets/css/select2.css" />
		<script src="/static/ace/assets/js/dropzone.min.js"></script>
		<script src="/static/ace/assets/js/select2.min.js"></script>
		<script src="/static/ace/assets/js/x-editable/bootstrap-editable.min.js"></script>
		<script src="/static/ace/assets/js/x-editable/ace-editable.min.js"></script>

		<script src="/static/ace/assets/js/markdown/markdown.min.js"></script>
		<script src="/static/ace/assets/js/markdown/bootstrap-markdown.min.js"></script>
		<script src="/static/derek/ajaxfileupload.js"></script>
<script>
D.DropZone = {
	init : function(){
		$('.dropzone').dropzone({
			paramName: "file", // The name that will be used to transfer the file
			maxFilesize: 5, // MB
			addRemoveLinks : true,
			dictDefaultMessage :
				'<span class="bigger-150 bolder"><i class="icon-caret-right red"></i> 拖动文件</span> 上传 \
				<span class="smaller-80 grey">(或者点击)</span> <br /> \
				<i class="upload-icon icon-cloud-upload blue icon-3x"></i>'
			,
			success : function(json){
				var json_string = json.xhr.response;
				if( json_string.length > 5 ){
					$('.contact-files').append('<input codekey="'+encodeURIComponent(json_string)+'" name="files[]" value="'+json_string+'" type="hidden" />');
				}
				return json.previewElement.classList.add("dz-success");
			},
			removedfile : function(file){
				var filepath = file.xhr.responseText;
				if( filepath ){
					D.ajax.get('?action=customer&operation=edit&act=delete_file&file=' + encodeURIComponent(filepath), function(json){
						if( json.data == 'ok' ){
							$('input[codekey="'+encodeURIComponent(filepath)+'"]').remove();
							var _ref;
							if ((_ref = file.previewElement) != null) {
							  _ref.parentNode.removeChild(file.previewElement);
							}
						}
					});
				}
				return this._updateMaxFilesReachedClass();
			},
			dictRemoveFile : '删除文件',
			dictResponseError: '在上传文件时出错!',
			//change the previewTemplate to use Bootstrap progress bars
			previewTemplate: "<div class=\"dz-preview dz-file-preview\">\n  <div class=\"dz-details\">\n    <div class=\"dz-filename\"><span data-dz-name></span></div>\n    <div class=\"dz-size\" data-dz-size></div>\n    <img data-dz-thumbnail />\n  </div>\n  <div class=\"progress progress-small progress-striped active\"><div class=\"progress-bar progress-bar-success\" data-dz-uploadprogress></div></div>\n  <div class=\"dz-success-mark\"><span></span></div>\n  <div class=\"dz-error-mark\"><span></span></div>\n  <div class=\"dz-error-message\"><span data-dz-errormessage></span></div>\n</div>"
		});
		try {
/*
			drop.on('success', function(json){
				  for (var p in json) {
					  console.log(p + ' = ' + json[p]);
					  if( typeof(json[p]) == 'object' ){
						  for( var n in json[p] ){
							  console.log(p + '[' + n + '] = ' + json[p][n]);
						  }
					  }
				  }
			});
*/
//			$('.dropzone').dropzone();
		} catch(e) {
		}
	}
}
D.Editable = {
	callfunc : {
		city : function(response, data){
			var box = $(this);
			var html = box.html();
			var name = $(this).attr('id');
			D.Editable.post(box, name, data);
		}
	},
	init : function(){
		//editables on first profile page
		$.fn.editable.defaults.mode = 'inline';
		$.fn.editableform.loading = "<div class='editableform-loading'><i class='light-blue icon-2x icon-spinner icon-spin'></i></div>";
	    $.fn.editableform.buttons = '<button type="submit" class="btn btn-info editable-submit"><i class="icon-ok icon-white"></i></button>'+
	                                '<button type="button" class="btn editable-cancel"><i class="icon-remove"></i></button>';    
		//editables 

		var maps = <?php echo json_encode($select_2_maps); ?>;
		$('#province').editable({
			mode: 'inline',
			type : 'select2',
			value : $('#province').attr('data'),
			source: maps['provinces'],
			success : function(response, data) {
				var box = $(this);
				var html = box.html();
				var name = $(this).attr('id');
				var province = $('#province').attr('data');

				if( province == data ){
					return false;
				}
				province = data;
				$('#province').attr('data', province);
//				$('#city').editable('destroy');
				D.Editable.post(box, name, data);
				D.ajax.get('?action=customer&operation=edit&act=public_get_city&dataid=' + province, function(json){
					if( json.data != null ){
						var sources = [];
						$.each(json.data, function(k, v){
							sources.push({id: v.id, text: v.name});
						});

						//so we remove it altogether and create a new element
						var city = $('#city').removeAttr('id').get(0);
						$(city).clone().attr('id', 'city').text('选择城市').editable({
							type: 'select2',
							value : null,
							source: sources,
							success : D.Editable.callfunc.city
						}).insertAfter(city);//insert it after previous instance
						$(city).remove();//remove previous instance
					}
				});
			}
		});
		$('#city').editable({
			mode: 'inline',
			type : 'select2',
			value : $('#city').attr('data'),
			source: maps['citys'],
			success : function(response, data) {
				var box = $(this);
				var html = box.html();
				var name = $(this).attr('id');
			}
		});

	    $('#demands').editable({
			mode: 'inline',
			type : 'select2',
			value : maps['demands_values'],
			source: maps['demands'],
			select2: {
				allowClear : true,
				multiple: true
			},
			success : function(response, data) {
				var box = $(this);
				var html = box.html();
				var name = $(this).attr('id');
				maps['demands_values'] = data;
				D.Editable.post(box, name, data);
			}
		});
	    $('#contact_job').editable({
			type: 'select2',
			value : $('#contact_job').attr('data'),
	        source: maps['jobs'],
			success: function(response, data) {
				var box = $(this);
				var name = $(this).attr('id');
				var currentValue = $('#contact_job').attr('data');
				if(currentValue == data) return false;
				currentValue = data;
				$('#contact_job').attr('data', currentValue);
				D.Editable.post(box, name, data);
			}
	    });
	    $('#status').editable({
			type: 'select2',
			value : $('#status').attr('data'),
	        source: maps['status'],
			success: function(response, data) {
				var box = $(this);
				var name = $(this).attr('id');
				var currentValue = $('#status').attr('data');
				if(currentValue == data) return false;
				currentValue = data;
				$('#status').attr('data', currentValue);
				D.Editable.post(box, name, data);
			}
	    });
	    $('#nature').editable({
			type: 'select2',
			value : $('#nature').attr('data'),
	        source: maps['natures'],
			success: function(response, data) {
				var box = $(this);
				var name = $(this).attr('id');
				var currentValue = $('#nature').attr('data');
				if(currentValue == data) return false;
				currentValue = data;
				$('#nature').attr('data', currentValue);
				D.Editable.post(box, name, data);
			}
	    });
	    $('.editable').editable({
			type: 'text',
			success : function(response, data) {
				var box = $(this);
				var html = box.html();
				var name = $(this).attr('id');
				if( name == 'name' && !data ){
					bootbox.alert('空值你也敢提交...什么心态');
					return false;
				}
				D.Editable.post(box, name, data);
			}
	    });
	},
	post : function(box, name, data, type){
		var post = {
			field : name,
			data : data
		};
		D.loading.bootbox();
		D.ajax.postdata('?action=customer&operation=edit&id=<?php echo $customer['id']; ?>&act=change_field', post, function(json){
			bootbox.hideAll();
			error = json.error;
			if( json.error ){
				bootbox.alert(json.data);
//				box.html(html);
			}
		});
	}
}
D.Main = {
	init : function(){

		$('.date-picker').datepicker({autoclose:true}).next().on(ace.click_event, function(){
			$(this).prev().focus();
		});

		$('[data-rel="tooltip"]').tooltip({container:'body'});
		$('#id-check-switch').removeAttr('checked').on('click', function(){
			$('.switch-div').addClass('hide');
			if( this.checked ){
				$('.switch-table').removeClass('hide');
			}else{
				$('.switch-row').removeClass('hide');
			}
		});
		$('.btn-post-one').on('click', function(){
			var type = $('input[name="type"]:checked').val();
			var content = $('textarea[name="content"]').val();
			if( !type ){
				bootbox.alert('请选择沟通方式');
				return false;
			}
			if( !content ){
				bootbox.alert('请填写沟通内容');
				return false;
			}
			var loading = bootbox.dialog({
				message: '<div class="tree-loading" style="text-align: center;"><i class="icon-refresh icon-spin blue"></i></div>' 
			});
			var data = $('#contact-form').serialize();
			D.ajax.postdata($('#contact-form').attr('action'), data, function(json){
				bootbox.hideAll();
				var buttons = json.error ? {
					danger : {
						label : "错误",
						className : "btn-sm btn-primary"
					}
				} : {
					success : {
						label : "OK",
						className : "btn-sm btn-primary",
						callback : function(){
							window.location.href = '?action=customer&operation=edit&detail=yes&id=<?php echo $customer['id']; ?>&qrt=profile';
						}
					}
				};
				bootbox.dialog({
					message: json.data, 
					buttons: buttons
				});
			});
//			D.ajax.postdata($('#contact-form').attr('action'), data, );
			return false;
		});
	}
}
</script>
<style>
.dropzone .dz-default.dz-message span{ display:inline !important;color: rgb(85, 85, 85); font-family:"微软雅黑"}
</style>
<?php if($_G['gp_qrt']){?>
<script>
D.QRT = {
	init : function(){
		$('.nav-tabs li a[href="#<?php echo $_G['gp_qrt']; ?>"]').click();
	}
}
</script>
<?php }?>
</body>
</html>
